package cn.mayaslight.wechat.api;

import org.apache.http.Header;

import cn.mayaslight.common.annotation.HttpWithEntity;
import cn.mayaslight.common.annotation.HttpWithHeader;
import cn.mayaslight.common.annotation.HttpWithParam;
import cn.mayaslight.common.param.IParamIn;
import cn.mayaslight.common.springbean.APICaller;
import cn.mayaslight.common.utils.JsonUtil;
import cn.mayaslight.wechat.api.bean.BaseResult;
import cn.mayaslight.wechat.api.bean.QyMessageSendResult;
import cn.mayaslight.wechat.api.bean.message.Message;
import cn.mayaslight.wechat.api.bean.message.QyMessage;

public class MessageAPI extends BaseAPI{
	
	/**
	 * 消息发送
	 * @param access_token
	 * @param message
	 * @return
	 */
	public static BaseResult messageCustomSend(String access_token,Message message){
		String str = JsonUtil.toJSONString(message);
		return messageCustomSend(access_token, str, BaseResult.class);
	}
	
	/**
	 * 企业号消息发送
	 * @param access_token
	 * @param message
	 * @return
	 */
	public static QyMessageSendResult qyMessageCustomSend(String accessToken, QyMessage message){
		String str = JsonUtil.toJSONString(message);
		return messageCustomSend(accessToken, str, QyMessageSendResult.class);
	}

	/**
	 * 消息发送
	 * @param access_token
	 * @param messageJson
	 * @return
	 */
	public static <T> T messageCustomSend(final String accessToken, final String messageJson, Class<T> targetType){
		return APICaller.call(new IParamIn() {
			
			@HttpWithEntity
			private String _messageJson = messageJson;
			
			@HttpWithHeader
			private Header header = jsonHeader;
			
			@HttpWithParam("access_token")
			private String _accessToken = accessToken;
			
			public String getApiKey() {
				// TODO Auto-generated method stub
				return null;
			}
		}, targetType);
	}

}